var serve = require('../serve')
var callBack = require('../tools')

//查询用户信息
var getUserInfo = function(req,res){
    serve.userModel.find((err,data)=>{
        if(err){
            callBack.cbStatusData(res,500,null)
            return
        }
        //console.log(data,data[0].userId)
        var x = serve.userModel.find({}).sort({_id:-1}).limit(1)
        console.log(x)
        callBack.cbStatusData(res,200,data)
    })
}

//添加用户信息
var addUserInfo = function(req,res){
    console.log(req.body)
    new serve.userModel(req.body).save((err,data)=>{
        if(err){
            callBack.cbStatusData(res,500,null)
            return
        }
        // serve.userModel.updateOne({"userName":data[0].userName},{"$inc":{"userId":1}},function(err,da){
        //     console.log(da)
        // })
        callBack.cbStatusData(res,200,data)
    })
}

//操作日志(支出,收入)
var oprateLog = function(req,res){
    console.log(req.body)
    new serve.tAccountModel(req.body).save((err,data)=>{
        if(err){
            callBack.cbStatusData(res,500,null)
            return
        }
        callBack.cbStatusData(res,200,data)
    })
}

var getOprateLog = function(req,res){
    serve.tAccountModel.find((err,data)=>{
        if(err){
            callBack.cbStatusData(res,500,null)
            return
        }
        callBack.cbStatusData(res,200,data)
    })
}

//房间创建
var roomCreat = function(req,res){
    console.log(req.body)
    new serve.roomModel(req.body).save((err,data)=>{
        if(err){
            callBack.cbStatusData(res,500,null)
            return
        }
    callBack.cbStatusData(res,200,data)
    })
}

var getRoomCreat = function(req,res){
    serve.roomModel.find((err,data)=>{
        if(err){
            callBack.cbStatusData(res,500,null)
            return
        }
    callBack.cbStatusData(res,200,data)
    })
}

module.exports = {
    getUserInfo,addUserInfo,oprateLog,roomCreat,getOprateLog,getRoomCreat
}